/**
 * @ClassName QuickSort
 * @Description TODO
 * @Author Quentin_zyj
 * @Date 2021/11/2 9:57
 */
public class QuickSort {
    public static void quickSort(int[] toSort, int low, int high) {
        if (low < high) {
            int pivot = getPivot(toSort, low, high);
            quickSort(toSort, low, pivot - 1);
            quickSort(toSort, pivot + 1, high);
        }
    }

    public static int getPivot(int[] array, int low, int high) {
        int temp = array[low];
        while (low < high) {
            while (low < high && array[high] >= temp) high--;
            array[low] = array[high];
            while (low < high && array[low] <= temp) low++;
            array[high] = array[low];
        }
        array[low] = temp;
        return low;
    }

    public static void main(String[] args) {
        int[] array = {5, 2, 3, 10, 98, 32, 33, 22};
        quickSort(array, 0, array.length - 1);
        for (int item : array) {
            System.out.print(item + " ");
        }
    }

}
